//
//  LXMiddleView.m
//  SevenFM
//
//  Created by seven on 2018/4/11.
//  Copyright © 2018年 seven. All rights reserved.
//

#import "LXMiddleView.h"
#import "CALayer+PauseAimate.h"

@interface LXMiddleView()

/**
 中间播放内容的视图
 */
@property (weak, nonatomic) IBOutlet UIImageView *middleImageView;

/**
 播放按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *playBtn;


@end

@implementation LXMiddleView

static LXMiddleView *_shareInstance;

+ (instancetype)shareInstance {

    if (_shareInstance == nil) {
        _shareInstance = [LXMiddleView middleView];
    }
    return _shareInstance;
}


+ (instancetype)middleView {
    NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
    LXMiddleView *middleView = [[currentBundle loadNibNamed:@"LXMiddleView" owner:nil options:nil] firstObject];
//    LXMiddleView *middleView = [[[NSBundle mainBundle] loadNibNamed:@"LXMiddleView" owner:nil options:nil] firstObject];
    return middleView;

}

- (void)awakeFromNib {
    [super awakeFromNib];

    self.middleImageView.layer.masksToBounds = YES;
    self.middleImg = self.middleImageView.image;

    [self.middleImageView.layer removeAnimationForKey:@"playAnnimation"];
    CABasicAnimation *basicAnnimation = [[CABasicAnimation alloc]init];
    basicAnnimation.keyPath = @"transform.rotation.z";
    basicAnnimation.fromValue = @0;
    basicAnnimation.toValue = @(M_PI * 2);
    basicAnnimation.duration = 30;
    basicAnnimation.repeatCount = MAXFLOAT;
    basicAnnimation.removedOnCompletion = NO;
    [self.middleImageView.layer addAnimation:basicAnnimation forKey:@"playAnnimation"];

    [self.middleImageView.layer pauseAnimate];

}

- (void)layoutSubviews {
    [super layoutSubviews];
//    self.layer.cornerRadius = self.frame.size.width * 0.5;
    self.middleImageView.layer.cornerRadius = self.middleImageView.frame.size.width * 0.5;
    self.middleImageView.layer.masksToBounds = YES;
}

@end
